package com.javaforever.clocksimplejee4.controller;
import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jiangnantaste.domain.Image;
import org.jiangnantaste.service.ImageService;
import org.jiangnantaste.serviceimpl.ImageServiceImpl;

public class ListAllImagesController extends HttpServlet {

	private static final long serialVersionUID = 8583953822538084029L;

	public ListAllImagesController() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}
	
	protected void processRequest(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			ImageService service = new ImageServiceImpl();
			List<Image> list = service.listAllImage();
			request.setAttribute("imageList", list);
			request.getRequestDispatcher("../jsp/pictureupload.jsp").forward(request, response);
		} catch (Exception e){
			e.printStackTrace();
		}
		 
	}

}
